package com.chenwei.rabbit.routingTopic;

import com.chenwei.rabbit.workQueues.Person;
import org.springframework.amqp.rabbit.annotation.Exchange;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.QueueBinding;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

/**
 * @author: chenwei
 * @date: 2021/4/1 18:02
 */
@Component("topicCustomer")
public class Customer {
    //消费者1
    @RabbitListener(
            bindings = {
                    @QueueBinding(
                            //创建临时队列
                            value = @Queue,
                            //定义交换机名称和 类型
                            exchange = @Exchange(value = "topicExchange",type = "topic"),
                            key = {"person.*"}
                    )
            }
    )
    public void getMsg1(Person message){
        System.out.println("消费者1接收到的消息："+message);
    }
    //消费者2
    @RabbitListener(
            bindings = {
                    @QueueBinding(
                            value = @Queue,
                            exchange = @Exchange(value = "topicExchange",type = "topic"),
                            key = {"person.#"}
                    )            }
    )
    public void getMsg2(Person message){
        System.out.println("消费者2接收到的消息："+message);
    }
}
